/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aip.assignment2.view.customer;

import aip.assignment2.persistence.entity.Product;
import aip.assignment2.persistence.entity.ProductCategory;
import aip.assignment2.service.ProductManager;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author Administrator
 */
@ManagedBean
@ViewScoped
public class Browser implements Serializable
{
	@EJB
	private ProductManager m_ProductManager;
	// <editor-fold desc="Property - maxCountOfProductPerPage - Get">
	/**
	 * the maximum count of product showed per page.
	 */
	private final int maxCountOfProductPerPage = 13;
	/**
	 * Gets the maximum count of product showed per page.
	 */
	public int getMaxCountOfProductPerPage()
	{
		return maxCountOfProductPerPage;
	}
	// </editor-fold>
	// <editor-fold desc="Property - maxCountOfProductInCartPerPage - Get">
	/**
	 * the maximum count of product in cart showed per page.
	 */
	private final int maxCountOfProductInCartPerPage = 10;
	/**
	 * Gets the maximum count of product in cart showed per page.
	 */
	public int getMaxCountOfProductInCartPerPage()
	{
		return maxCountOfProductInCartPerPage;
	}
	// </editor-fold>
	// <editor-fold desc="Property - currentProductCategory - Get/Set">
	/**
	 * the current selected ProductCategory
	 */
	private ProductCategory currentProductCategory = null;
	/**
	 * Gets the current selected ProductCategory.
	 */
	public ProductCategory getCurrentProductCategory()
	{
		return currentProductCategory;
	}
	/**
	 * Sets the current selected ProductCategory.
	 */
	public void setCurrentProductCategory(ProductCategory productCategory)
	{
		currentProductCategory = productCategory;
	}
	// </editor-fold>
	// <editor-fold desc="Property - currentProduct - Get/Set">
	/**
	 * the current selected Product
	 */
	private Product currentProduct =null;
	/**
	 * Gets the current selected Product.
	 */
	public Product getCurrentProduct()
	{
		return currentProduct;
	}
	/**
	 * Sets the current selected Product.
	 */
	public void setCurrentProduct(Product currentProduct)
	{
		this.currentProduct = currentProduct;
	}
	// </editor-fold>
	
	@PostConstruct
	public void initialize()
	{
		currentProductCategory = m_ProductManager.getProductCategories().get(0);
	}
	
	public ProductCategory getProductCategoryByName(String name)
	{
		return m_ProductManager.getProductCategoryByName(name);
	}
	
	public List<Product> getProductsOfCurrentProductCategory()
	{
		return currentProductCategory.getProductList();
	}
	public List<ProductCategory> getProductCategories()
	{
		return m_ProductManager.getProductCategories();
	}
	
	
	
	public String gotoNextPage()
	{
		return "cart";
	}
	//private int currentProgress = 1;
	//public int getCurrentProgress()
	//{
	//	return currentProgress;
	//}
	//public void setCurrentProgress(int currentProgress)
	//{
	//	this.currentProgress = currentProgress;
	//}
	public String goToProgress(int progress)
	{
		//currentProgress = progress;
		switch (progress)
		{
		case 1:
			return "category";
		case 2:
			return "cart";
		case 3:
			return "checkout";
		case 4:
			return "confirm";
		case 5:
			return "success";
		case 6:
			return "admin";
		case 7:
			return "supplier";
		case 8:
			return "index";
		case 9:
			return "customerSearchOrder";
		default:
			return "null";
		}
	}
	
}
